app.controller('addCommodityContorller', ['$scope','ajax','$state',function ($scope,ajax,$state) {

    //添加商品分类
    ajax.get({
        url: 'back/commodityCategory/list',
        data:{
            level:1
        },
        debug: false
    }).then(function (data) {
        $scope.f_class=data;
        $scope.$watch('f.name', function(data) {
            if($scope.f){
                ajax.get({
                    url: 'back/commodityCategory/list',
                    data:{
                        parentId:$scope.f.name.categoryId
                    },
                    debug: false
                }).then(function (data) {
                    $scope.s_class=data;
                    $scope.s={
                        obj:data
                    };
                    $scope.$watch('s.name', function(data1) {
                    });
                })
            }
        });
    })


//提交商品
    $scope.commodityDetai = function(data){
            data.categoryId=$scope.s.name.categoryId;
            ajax.post({
                url: 'back/commodity/add',
                data: data,
                debug: true
            }).then(function(){
                Flash.create('success','添加成功', 'custom-class');
                $state.go('admin.commodity')
            })
    }

}]);
